﻿using System;
using System.Windows;
using System.Windows.Controls;
//using SomethingSpacialClassLib.Web;
using SomethingSpacial.Web;
using SomethingSpacial.ViewModel;
using SomethingSpacial.Model;

namespace SomethingSpacial.Views.Admin
{
    public partial class SponsorList : Page
    {

        SomethingSpacialContext domainContext = new SomethingSpacialContext();

        public SponsorList()
        {
            InitializeComponent();
            Loaded +=new RoutedEventHandler(SponsorList_Loaded);
        }

        #region "Page Events"

        void SponsorList_Loaded(object sender, RoutedEventArgs e)
        {
            ((SponsorsViewModel)this.DataContext).loadSponsors();
        }


        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            editDataForm.CommitEdit();

            if (editDataForm.CurrentItem != null)
            {
                SponsorModel sm = editDataForm.CurrentItem as SponsorModel;
                ((SponsorsViewModel)this.DataContext).UpdateSponsor(sm);
            }
        }

        private void AddNew_Click(object sender, RoutedEventArgs e)
        {
            var w = new SponsorAdd();
            w.Closed += addNewWindow_Closed;
            w.Show();
        }

        void addNewWindow_Closed(object sender, EventArgs e)
        {

            SponsorAdd addForm = (SponsorAdd)sender;
            if (addForm.NewSponsor != null)
            {
                ((SponsorsViewModel)this.DataContext).addSponsor(addForm.NewSponsor);
            }

        }

        #endregion





    }
}
